# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Contributor: 7heo <7heo@mail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=gogs
pkgver=0.13.0
pkgrel=11
pkgdesc="Painless self-hosted Git service"
url="https://gogs.io/"
arch="all"
license="MIT"
depends="git"
makedepends="go perl sqlite-dev"
install="$pkgname.pre-install"
pkgusers="gogs"
pkggroups="www-data"
options="chmod-clean !check" # go race fails
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/gogs/gogs/archive/refs/tags/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.ini"

# secfixes:
#   0.13.0-r0:
#     - CVE-2022-32174
#   0.12.9-r0:
#     - CVE-2022-1285
#   0.12.7-r0:
#     - CVE-2022-1464
#   0.12.6-r0:
#     - CVE-2022-0870
#     - CVE-2022-0871

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go build -v -tags "sqlite redis memcache cert libsqlite3"
}

package() {
	install -dm755 "$pkgdir"/usr/share/webapps/$pkgname

	# TODO: Is it really necessary to be world-readable?!
	install -dm755 -o gogs -g www-data \
		"$pkgdir"/var/lib/$pkgname \
		"$pkgdir"/var/lib/$pkgname/git \
		"$pkgdir"/var/lib/$pkgname/db \
		"$pkgdir"/var/lib/$pkgname/avatars \
		"$pkgdir"/var/lib/$pkgname/attachements \
		"$pkgdir"/var/cache/$pkgname/sessions \
		"$pkgdir"/var/log/$pkgname \
		"$pkgdir"/etc/$pkgname/conf

	install -Dm755 $pkgname "$pkgdir"/usr/bin/$pkgname

	install -Dm664 -o gogs -g www-data "$srcdir"/$pkgname.ini \
		"$pkgdir"/etc/$pkgname/conf/app.ini

	mv public templates "$pkgdir"/usr/share/webapps/$pkgname/

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
3aabee328c8c98102d9895d8ff1990e5a28460256189037e32eda8ab695c9590d8e5252062da23a78780e4c95b5cec971d10c76a1fe2e62569ad84efaa322871  gogs-0.13.0.tar.gz
2a6da846e1996925311e3d18fb562cd861a59565cb93049e949b08ff8f2dad4c9d8f7a324df751303bccb19ed1efc895fbe848ae0b5db87380b7f92612b415df  gogs.initd
52ce41c05c263b790221a04d13d2eb9bba689e4bd72daf5b6af31416e80a485a46bae19e18581d7bde879307283847e6486686a2fe4140fe38ebb6f315e11a86  gogs.confd
1d8cc4d9c96887de50d281f49d7f0bae963318a56a9e6cc46052d72236e446d20eb6228b8f51e24d5dbe63bf459040fb3556e9554fa242f3bef3969e11d18b06  gogs.ini
"
